package com.ruoyi.ebike.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ebike.domain.GiftCard;
import com.ruoyi.ebike.service.IGiftCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 礼品卡配置Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/giftcard/giftcard")
public class GiftCardController extends BaseController
{
    @Autowired
    private IGiftCardService giftCardService;

    /**
     * 查询礼品卡配置列表
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:list')")
    @GetMapping("/list")
    public TableDataInfo list(GiftCard giftCard)
    {
        startPage();
        List<GiftCard> list = giftCardService.selectGiftCardList(giftCard);
        return getDataTable(list);
    }

    /**
     * 导出礼品卡配置列表
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:export')")
    @Log(title = "礼品卡配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GiftCard giftCard)
    {
        List<GiftCard> list = giftCardService.selectGiftCardList(giftCard);
        ExcelUtil<GiftCard> util = new ExcelUtil<GiftCard>(GiftCard.class);
        util.exportExcel(response, list, "礼品卡配置数据");
    }

    /**
     * 获取礼品卡配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(giftCardService.selectGiftCardById(id));
    }

    /**
     * 新增礼品卡配置
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:add')")
    @Log(title = "礼品卡配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GiftCard giftCard)
    {
        return toAjax(giftCardService.insertGiftCard(giftCard));
    }

    /**
     * 修改礼品卡配置
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:edit')")
    @Log(title = "礼品卡配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GiftCard giftCard)
    {
        return toAjax(giftCardService.updateGiftCard(giftCard));
    }

    /**
     * 删除礼品卡配置
     */
    @PreAuthorize("@ss.hasPermi('giftcard:giftcard:remove')")
    @Log(title = "礼品卡配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(giftCardService.deleteGiftCardByIds(ids));
    }
}
